/*
 *
 * SimplePCR1000 (Qt4) Version 1.x
 * Copyright (C) 2011  Tyler H. Jones (me@tylerjones.me)
 * http://www.thebasementserver.com/
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

#include "appsettings.h"

//Default constructor
AppSettings::AppSettings(QObject* parent)
{
}

    /*---------------------------------------------------------------
    ----Get/Set Settings
    ----------------------------------------------------------------*/
        QVariant AppSettings::get(QString name)
        {
            QSettings tmp(APP_COMPANY, APP_NAME);
            if(name==S_FIRSTRUN) {
                return tmp.value(name, true);
            } else if(name==S_PORT) {
                return tmp.value(name, DEFAULT_ComPort);
            } else if(name==S_FREQ) {
                return tmp.value(name, "100");
            } else if(name==S_VOL) {
                return tmp.value(name, "85");
            } else if(name==S_DATARATE) {
                return tmp.value(name, "9600"); // B/s
            } else if(name==S_SQU) {
                return tmp.value(name, "127");
            } else if(name==S_MODE) {
                return tmp.value(name, "AM");
            } else if(name==S_FILTER) {
                return tmp.value(name, "3KHz");
            } else if(name==S_IFSHIFT) {
                return tmp.value(name, "127");
            } else if(name==S_SCAN_IVAL) {
                return tmp.value(name, "250"); // ms
            } else if(name==S_DELAY_IVAL) {
                return tmp.value(name, "3000"); // ms
            } else if(name==S_MUTE) {
                return tmp.value(name, false);
            } else if(name==S_NB) {
                return tmp.value(name, false);
            } else if(name==S_AGC) {
                return tmp.value(name, false);
            } else if(name==S_VSC) {
                return tmp.value(name, false);
            } else if(name==S_ATTEN) {
                return tmp.value(name, false);
            } else if(name==S_SCAN) {
                return tmp.value(name, false);
            } else if(name==S_STARTHIDDEN) {
                return tmp.value(name, false);
            } else if(name==S_STARTON) {
                return tmp.value(name, false);
            } else if(name==S_CHANNOTIF) {
                return tmp.value(name, false);
            } else {
                qDebug() << "Value not in config!";
                return -1;
            }
            return 0;
        }

        void AppSettings::set(QString name, QVariant val)
        {

            QSettings tmp(APP_COMPANY, APP_NAME);
            if(name==S_FIRSTRUN) {
                tmp.setValue(S_FIRSTRUN, val.toBool());
            } else if(name==S_PORT) {
                tmp.setValue(S_PORT, COM.qvar(val));
            } else if(name==S_FREQ) {
                tmp.setValue(S_FREQ, COM.qvar(val));
            } else if(name==S_VOL) {
                tmp.setValue(S_VOL, COM.qvar(val));
            } else if(name==S_DATARATE) {
                tmp.setValue(S_DATARATE, COM.qvar(val));
            } else if(name==S_SQU) {
                tmp.setValue(S_SQU, COM.qvar(val));
            } else if(name==S_FILTER) {
                tmp.setValue(S_FILTER, COM.qvar(val));
            } else if(name==S_MODE) {
                tmp.setValue(S_MODE, COM.qvar(val));
            } else if(name==S_IFSHIFT) {
                tmp.setValue(S_IFSHIFT, COM.qvar(val));
            } else if(name==S_SCAN_IVAL) {
                tmp.setValue(S_SCAN_IVAL, COM.qvar(val));
            } else if(name==S_DELAY_IVAL) {
                tmp.setValue(S_DELAY_IVAL, COM.qvar(val));
            } else if(name==S_MUTE) {
                tmp.setValue(S_MUTE, val.toBool());
            } else if(name==S_NB) {
                tmp.setValue(S_NB, val.toBool());
            } else if(name==S_AGC) {
                tmp.setValue(S_AGC, val.toBool());
            } else if(name==S_VSC) {
                tmp.setValue(S_VSC, val.toBool());
            } else if(name==S_ATTEN) {
                tmp.setValue(S_ATTEN, val.toBool());
            } else if(name==S_SCAN) {
                tmp.setValue(S_SCAN, val.toBool());
            } else if(name==S_STARTON) {
                tmp.setValue(S_STARTON, val.toBool());
            } else if(name==S_STARTHIDDEN) {
                tmp.setValue(S_STARTHIDDEN, val.toBool());
            } else if(name==S_CHANNOTIF) {
                tmp.setValue(S_CHANNOTIF, val.toBool());
            } else {
                qDebug() << "Value not in config!";
                return;
            }
        }

        void AppSettings::RestoreDefaults() {
            QSettings tmp(APP_COMPANY, APP_NAME);
            tmp.setValue(S_FIRSTRUN,true);
            tmp.setValue(S_PORT, DEFAULT_ComPort);
            tmp.setValue(S_FREQ, 100);
            tmp.setValue(S_VOL, 85);
            tmp.setValue(S_DATARATE, 9600);
            tmp.setValue(S_SQU, 127);
            tmp.setValue(S_FILTER, "3KHz");
            tmp.setValue(S_MODE, "AM");
            tmp.setValue(S_IFSHIFT, 127);
            tmp.setValue(S_SCAN_IVAL, 250);
            tmp.setValue(S_DELAY_IVAL, 3000);
            tmp.setValue(S_MUTE, false);
            tmp.setValue(S_NB, false);
            tmp.setValue(S_AGC, false);
            tmp.setValue(S_VSC, false);
            tmp.setValue(S_ATTEN, false);
            tmp.setValue(S_SCAN, false);
            tmp.setValue(S_STARTON, false);
            tmp.setValue(S_STARTHIDDEN, false);
            tmp.setValue(S_CHANNOTIF, false);
        }

